package com.jkj.http.sys.service.impl;

import java.util.Date;

import cn.hutool.core.date.DateUtil;
import com.jkj.http.sys.dao.SysUserDao;
import com.jkj.http.sys.dao.SysUserLogOnDao;
import com.jkj.http.sys.entity.SysUser;
import com.jkj.http.sys.entity.SysUserLogOn;
import com.jkj.http.sys.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class AccountServiceImp implements AccountService {
	@Autowired
	private SysUserDao sysUserDao;
	@Autowired
	private SysUserLogOnDao sysUserLogOnDao;
	
	@Override
	public SysUser getByUserName(String userName) {
		return sysUserDao.getByUserName(userName);
	}
	@Override
	public int updateLogin(SysUserLogOn model) {
		model.setIsOnLine("1");
        model.setLastVisitTime(DateUtil.date());
        model.setPrevVisitTime(model.getLastVisitTime());
        model.setLoginCount(model.getLoginCount()+1);
		return sysUserLogOnDao.updateLogin(model);
	}
	
	@Override
	public SysUserLogOn getByAccount(String userId) {
		return sysUserLogOnDao.getByAccount(userId);
	}
	@Override
	public SysUser getUser(String userId) {
		return sysUserDao.get(userId);
	}
	@Override
	public int modifyPwd(SysUserLogOn userLoginEntity) {
		userLoginEntity.setChangePwdTime(DateUtil.date());
		return sysUserLogOnDao.modifyPwd(userLoginEntity);
	}
	@Override
	public int updateBasicInfo(SysUser model) {
		model.setModifyTime(DateUtil.date());
		return sysUserDao.updateBasicInfo(model);
	}

}
